package com.ruoyi.web.controller.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.framework.web.service.AppLoginUser;
import com.ruoyi.framework.web.service.AppTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api")
public class AppLoginService {
    @Autowired
    private AppTokenService appTokenService;
    @Anonymous
    @PostMapping("/login")
    public AjaxResult login(){
        AppLoginUser appLoginUser = new AppLoginUser();
        appLoginUser.setUserId(1L);
        SysUser sysUser = new SysUser();
        sysUser.setUserName("test");
        appLoginUser.setUser(sysUser);
        String token = appTokenService.createToken(appLoginUser);
        return AjaxResult.success("suc", token);
    }
    @GetMapping("test")
    public AjaxResult test(){
        return AjaxResult.success("test");
    }
}
